package com.ys.erp.stage_shop_service.controller;

import com.ys.erp.framework.annotation.CheckEmpLogin;
import com.ys.erp.framework.annotation.ResponseResult;
import com.ys.erp.framework.annotation.StageLoginEmp;
import com.ys.erp.framework.bean.dto.StageEmpDTO;
import com.ys.erp.framework.response.PageDTO;
import com.ys.erp.stage_shop_service.bean.condition.MarkErrorFixedCondition;
import com.ys.erp.stage_shop_service.bean.condition.ZfbSeparateAccountOrderCon;
import com.ys.erp.stage_shop_service.bean.condition.ZfbSeparateAccountStatCon;
import com.ys.erp.stage_shop_service.bean.vo.*;
import com.ys.erp.stage_shop_service.service.ShopSeparateAccountService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author minamiyama
 * @date 2025/6/18 14:20
 */
@ResponseResult
@RestController
@RequiredArgsConstructor
@RequestMapping("/manage/shop/separateAccount")
@Tag(name = "店铺微分呗分账相关接口", description = "店铺微分呗分账相关接口")
public class ShopSeparateAccountController {

    private final ShopSeparateAccountService shopSeparateAccountService;

    @Operation(summary = "查询待转账任务队列")
    @GetMapping("/getPendingTasks")
    @CheckEmpLogin
    public List<ZfbWaitSeparateAccountVO> getPendingTasks(@StageLoginEmp StageEmpDTO empDto) {
        return shopSeparateAccountService.getPendingTasks();
    }

    @Operation(summary = "查询转账确认中任务")
    @GetMapping("/getConfirmingTasks")
    @CheckEmpLogin
    public List<ZfbOrderOkIngVO> getConfirmingTasks(@StageLoginEmp StageEmpDTO empDto) {
        return shopSeparateAccountService.getConfirmingTasks();
    }

    @Operation(summary = "查询转账异常任务")
    @GetMapping("/getErrorTasks")
    @CheckEmpLogin
    public List<ZfbSeparateAccountFailVO> getErrorTasks(@StageLoginEmp StageEmpDTO empDto) {
        return shopSeparateAccountService.getErrorTasks();
    }

    @Operation(summary = "标记异常任务为已修正并重新加入队列")
    @PostMapping("/markErrorFixed")
    @CheckEmpLogin
    public void markErrorFixed(@Valid @RequestBody MarkErrorFixedCondition markErrorFixedCondition,
                               @StageLoginEmp StageEmpDTO empDto) {
        shopSeparateAccountService.markErrorFixed(markErrorFixedCondition);
    }

    @Operation(summary = "分页查询支付宝分账订单")
    @PostMapping("/getZfbSeparateAccountOrderPage")
    @CheckEmpLogin
    public PageDTO<ZfbSeparateAccountOrderPageVO> getZfbSeparateAccountOrderPage(@Valid @RequestBody ZfbSeparateAccountOrderCon queryDTO,
                                                                                 @StageLoginEmp StageEmpDTO empDto) {
        return shopSeparateAccountService.getZfbSeparateAccountOrderPage(queryDTO);
    }

    @Operation(summary = "查询分账名单")
    @GetMapping("/getSeparateAccountList")
    @CheckEmpLogin
    public List<SeparateAccountListVO> getSeparateAccountList(@StageLoginEmp StageEmpDTO empDto) {
        return shopSeparateAccountService.getSeparateAccountList();
    }

    // ==================== 统计相关接口 ====================

    @Operation(summary = "获取分账总体统计数据")
    @PostMapping("/getOverallStat")
    @CheckEmpLogin
    public ZfbSeparateAccountOverallStatVO getOverallStat(@Valid @RequestBody ZfbSeparateAccountStatCon queryDTO,
                                                          @StageLoginEmp StageEmpDTO empDto) {
        return shopSeparateAccountService.getOverallStat(queryDTO);
    }

    @Operation(summary = "获取分账时间维度统计数据")
    @PostMapping("/getTimeStat")
    @CheckEmpLogin
    public PageDTO<ZfbSeparateAccountTimeStatVO> getTimeStat(@Valid @RequestBody ZfbSeparateAccountStatCon queryDTO,
                                                             @StageLoginEmp StageEmpDTO empDto) {
        return shopSeparateAccountService.getTimeStat(queryDTO);
    }

    @Operation(summary = "获取分账店铺维度统计数据")
    @PostMapping("/getShopStat")
    @CheckEmpLogin
    public PageDTO<ZfbSeparateAccountShopStatVO> getShopStat(@Valid @RequestBody ZfbSeparateAccountStatCon queryDTO,
                                                             @StageLoginEmp StageEmpDTO empDto) {
        return shopSeparateAccountService.getShopStat(queryDTO);
    }

    @Operation(summary = "获取分账支付宝账户维度统计数据")
    @PostMapping("/getAccountStat")
    @CheckEmpLogin
    public PageDTO<ZfbSeparateAccountAccountStatVO> getAccountStat(@Valid @RequestBody ZfbSeparateAccountStatCon queryDTO,
                                                                   @StageLoginEmp StageEmpDTO empDto) {
        return shopSeparateAccountService.getAccountStat(queryDTO);
    }

    @Operation(summary = "获取分账比例维度统计数据")
    @PostMapping("/getRatioStat")
    @CheckEmpLogin
    public PageDTO<ZfbSeparateAccountRatioStatVO> getRatioStat(@Valid @RequestBody ZfbSeparateAccountStatCon queryDTO,
                                                               @StageLoginEmp StageEmpDTO empDto) {
        return shopSeparateAccountService.getRatioStat(queryDTO);
    }

    @Operation(summary = "获取分账综合统计数据（包含所有维度TOP 10）")
    @PostMapping("/getComprehensiveStat")
    @CheckEmpLogin
    public ZfbSeparateAccountComprehensiveStatVO getComprehensiveStat(@Valid @RequestBody ZfbSeparateAccountStatCon queryDTO,
                                                                      @StageLoginEmp StageEmpDTO empDto) {
        return shopSeparateAccountService.getComprehensiveStat(queryDTO);
    }
}
